package cn.sc.allinpay.allfavour.business.check;

import android.os.Bundle;
import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.widget.DecorationVert;
import cn.sc.allinpay.allfavour.business.common.adapter.CheckCouponAdapter;
import cn.sc.allinpay.allfavour.business.common.adapter.CheckRemarkAdapter;
import cn.sc.allinpay.allfavour.business.common.data.CheckCouponData;


/**
 * activity 验券
 * author：pany
 * on 2017/12/1 11:14
 */
public class CheckActivity extends BaseActivity<CheckContract.View, CheckContract.Presenter>
        implements CheckContract.View, CheckCouponAdapter.OnAdapterListener {

    @BindView(R.id.spRemark)
    AppCompatSpinner spRemark;
    @BindView(R.id.recycler)
    RecyclerView recycler;
    private CheckCouponAdapter couponsAdapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_check;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("验券");
    }

    @Override
    protected CheckContract.Presenter bindPresenter() {
        return new CheckPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        recycler.addItemDecoration(new DecorationVert(this, R.dimen.margin_common, R.dimen.margin_common));
        recycler.setLayoutManager(new LinearLayoutManager(this));// 列表布局
        couponsAdapter = new CheckCouponAdapter();
        couponsAdapter.setOnAdapterListener(this);
        recycler.setAdapter(couponsAdapter);
    }

    @OnClick(R.id.btnConfirm)
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnConfirm:
                presenter.startCheckDetailActivity();
                break;
        }
    }

    @Override
    public void onDataChange() {

    }

    @Override
    public void setRemarkAdapter(List<String> remarks) {
        spRemark.setAdapter(new CheckRemarkAdapter(this, remarks));
    }

    @Override
    public String getSelectRemark() {
        if (spRemark.getSelectedItemPosition() == 0) {
            return "";
        }
        return (String) spRemark.getSelectedItem();
    }

    @Override
    public void couponsAdapterChange(List<CheckCouponData> datas) {
        couponsAdapter.change(datas);
    }

    @Override
    public List<CheckCouponData> getCouponsAdapterDatas() {
        return couponsAdapter.getDatas();
    }

}
